export default {
  name: "KTableColumn",
  componentName: 'KTableColumn',
  props: {
    prop: String,
    label: String,
    sortable: Boolean,
  },
  computed: {
    columnOrTableParent() {
      let parent = this.$parent
      while (parent && !parent.tableId) parent = parent.$parent
      return parent
    },
  },
  watch: {
    prop(val) {
      this.column.prop = val
    },
    label(val) {
      this.column.lable = val
    },
    sortable(val) {
      this.column.sortable = val
    },
  },
  data() {
    return {
      column: {},
    }
  },
  created() {
    let column = {
      ...this.$props,
    }
    let self = this
    column.renderCell = (h, data) => {
      let render = (h, data) => data.row[column.prop]

      if (self.$scopedSlots.default) {
        render = () => self.$scopedSlots.default(data)
      }

      return render(h, data)
    }

    this.column = column
  },
  mounted() {
    const columns = this.columnOrTableParent.columns
    columns.push(this.column)
  },

  render(h) {
  }
}
